package com.burstly.lib.component.networkcomponent.burstly;

import android.app.Activity;
import android.content.Context;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import com.burstly.lib.component.networkcomponent.IActivityLifeCycleAware;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;

public abstract class OverlayContainer<T extends View,  extends IActivityLifeCycleAware>
  implements IActivityLifeCycleAware, IOverlayContainer
{
  protected static final LoggerExt LOG = LoggerExt.getInstance();
  protected static final String TAG = OverlayContainer.class.getSimpleName();
  private Context mActiveContext;
  private boolean mApplyInOutAnimation = true;
  private final T mChildView;
  protected View mCloseableContainer;
  private ViewGroup mContainerLayout;
  private IOverlayListener mOverlayListener;
  private ViewGroup mParentView;
  private boolean mRemoveOverlayedChildren = true;
  private boolean mShowing;

  public OverlayContainer(ViewGroup paramViewGroup, T paramT)
  {
    this.mParentView = paramViewGroup;
    this.mChildView = paramT;
    Utils.checkNotNull(paramT, "Child view can not be null.");
    Utils.checkNotNull(paramViewGroup, "Parent view can not be null.");
    this.mActiveContext = paramViewGroup.getContext();
  }

  private void onHideOverlayed()
  {
    if (this.mRemoveOverlayedChildren)
    {
      int i = 0;
      int j = this.mParentView.getChildCount();
      while (i < j)
      {
        this.mParentView.getChildAt(i).setVisibility(0);
        i++;
      }
    }
  }

  private void onShowOverlayed()
  {
    if (this.mRemoveOverlayedChildren)
    {
      int i = 0;
      int j = this.mParentView.getChildCount();
      while (i < j)
      {
        this.mParentView.getChildAt(i).setVisibility(8);
        i++;
      }
    }
  }

  protected abstract View addChildToLayout(ViewGroup paramViewGroup, T paramT);

  protected abstract ViewGroup createContainerLayout();

  public T getChildView()
  {
    return this.mChildView;
  }

  public ViewGroup getContainerLayout()
  {
    if (this.mContainerLayout == null)
    {
      this.mContainerLayout = createContainerLayout();
      this.mCloseableContainer = addChildToLayout(this.mContainerLayout, this.mChildView);
    }
    return this.mContainerLayout;
  }

  public Context getContext()
  {
    return this.mActiveContext;
  }

  public IOverlayListener getOverlayListener()
  {
    return this.mOverlayListener;
  }

  public ViewGroup getParentView()
  {
    return this.mParentView;
  }

  public void hideOverlayed()
  {
    if (this.mShowing)
    {
      if ((this.mContainerLayout != null) && (this.mParentView != null))
      {
        onHideOverlayed();
        this.mParentView.removeView(this.mContainerLayout);
        if (this.mApplyInOutAnimation)
          this.mContainerLayout.startAnimation(AnimationUtils.makeOutAnimation(getContext(), false));
      }
      this.mShowing = false;
      if (this.mOverlayListener != null)
        this.mOverlayListener.onCloseOverlay();
    }
  }

  public boolean isApplyInOutAnimation()
  {
    return this.mApplyInOutAnimation;
  }

  public boolean isRemoveOverlayedChildren()
  {
    return this.mRemoveOverlayedChildren;
  }

  public boolean isShowing()
  {
    return this.mShowing;
  }

  public void onDestroy(Activity paramActivity)
  {
    ((IActivityLifeCycleAware)this.mChildView).onDestroy(paramActivity);
  }

  public boolean onKey(Activity paramActivity, int paramInt, KeyEvent paramKeyEvent)
  {
    return ((IActivityLifeCycleAware)this.mChildView).onKey(paramActivity, paramInt, paramKeyEvent);
  }

  public void onPause(Activity paramActivity)
  {
    ((IActivityLifeCycleAware)this.mChildView).onPause(paramActivity);
  }

  public void onResume(Activity paramActivity)
  {
    ((IActivityLifeCycleAware)this.mChildView).onResume(paramActivity);
  }

  public void setApplyInOutAnimation(boolean paramBoolean)
  {
    this.mApplyInOutAnimation = paramBoolean;
  }

  public void setOverlayListener(IOverlayListener paramIOverlayListener)
  {
    this.mOverlayListener = paramIOverlayListener;
  }

  public void setParentView(ViewGroup paramViewGroup)
  {
    this.mParentView = paramViewGroup;
  }

  public void setRemoveOverlayedChildren(boolean paramBoolean)
  {
    this.mRemoveOverlayedChildren = paramBoolean;
  }

  public void showOverlayed()
  {
    if (!this.mShowing)
    {
      if (this.mParentView == null)
        break label72;
      ViewGroup localViewGroup = getContainerLayout();
      onShowOverlayed();
      this.mParentView.addView(localViewGroup);
      if (this.mApplyInOutAnimation)
        localViewGroup.startAnimation(AnimationUtils.makeInAnimation(getContext(), false));
    }
    while (true)
    {
      this.mShowing = true;
      if (this.mOverlayListener != null)
        this.mOverlayListener.onShowOverlay();
      return;
      label72: LOG.logWarning(TAG, "Can not show overlayed view due its top most parent has not been set before.", new Object[0]);
    }
  }

  public static abstract interface IOverlayListener
  {
    public abstract void onCloseOverlay();

    public abstract void onShowOverlay();
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.OverlayContainer
 * JD-Core Version:    0.6.2
 */